<template>
  <div class="app-container">
    <template>
      <div class="right-detail">
        <div class="cbox">
          <el-form class="form" :model="queryParam" ref="queryParam" :rules="rules" :inline="true" size="mini">
            <!-- <el-row :gutter="12" class="row"> -->
            <!-- <el-col :span="4"> -->
            <el-form-item size="mini" label="标的编号:" prop="bidCode">
              <el-input clearable v-model="queryParam.bidCode" size="mini" style="width: 180px"></el-input>
            </el-form-item>
            <!-- </el-col> -->
            <!-- <el-col :span="4"> -->
            <el-form-item size="mini" label="审核状态:" prop="bidAuditstatus">
              <el-select clearable v-model="queryParam.bidAuditstatus" style="width: 180px" placeholder="请选择">
                <el-option v-for="(item, index) in statusList" :key="index" :value="item.code" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <!-- </el-col> -->
            <!-- <el-col :span="2"> -->
            <el-form-item>
              <el-button @click="searchType" type="primary">查询</el-button>
            </el-form-item>
            <!-- </el-col> -->
            <!-- </el-row> -->
          </el-form>
        </div>
        <split-pane split="horizontal" v-on:resize="resize" :default-percent="55" :max-percent="80">
          <!-- 上半部分 -->
          <template slot="paneL">
            <div class="top-type" ref="topType" style="top: 49%">
              <div class="btn-area" ref="btnArea">
                <buttonName @clickEvent="clickEventDom"></buttonName>
                <!-- <el-button plain size="mini" type="primary" v-if="isAuth('auditButton')" @click="auditButton">审核</el-button>
                <el-button plain size="mini" type="primary" v-if="isAuth('delAuditButton')" @click="delAuditButton">取消审核</el-button>-->
              </div>

              <!-- 状态（E-启用 N-未启用 D-停用） -->
              <el-table
                :data="TypeList"
                :height="typeHeight"
                highlight-current-row
                class="demand"
                @row-click="getCurrentTypeRow"
                border
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{}"
              >
                <el-table-column size="mini" show-overflow-tooltip type="index" label="序号" align="center" width="60">
                  <template slot-scope="scope">
                    <span>{{ (Pagination.currentPage - 1) * Pagination.pageSize + scope.$index + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="审核状态" prop="bidAuditstatus" width="100" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <span v-if="scope.row.bidAuditstatus == 'N'">未审核</span>
                    <span v-if="scope.row.bidAuditstatus == 'Y'">已审核</span>
                  </template>
                </el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidCode" width="120" align="center" label="标的编号"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidType" width="80" align="center" label="标的类型"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidName" align="center" width="220" label="标的名称"></el-table-column>
                <el-table-column align="center" label="是否与平台合作" prop="bidPlatformTogether" width="200" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <span v-if="scope.row.bidPlatformTogether == 'N'">否</span>
                    <span v-if="scope.row.bidPlatformTogether == 'Y'">是</span>
                  </template>
                </el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidAmount" align="center" label="运输总量（吨）" width="130"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidQuotations" align="left" width="80" label="竞价方式"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="bidOffer" align="center" label="单价竞价范围（元/吨）" width="160"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" width="120" prop="dptName" label="标的来源"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip header-align="left" align="left" prop="bidRemark" label="备注"></el-table-column>
              </el-table>
              <div>
                <el-pagination
                  class="pagination"
                  small
                  background
                  ref="pagination"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="Pagination.currentPage"
                  :page-sizes="Pagination.pageSizeList"
                  :page-size="Pagination.pageSize"
                  :layout="Pagination.layout"
                  :total="Pagination.total"
                ></el-pagination>
              </div>
            </div>
          </template>

          <!-- 下半部分 -->
          <template slot="paneR">
            <div class="codeNumberCode" style="background-color: #fff">需求信息</div>
            <div class="bottom-code" ref="bottomCode" style="background-color: #fff">
              <!-- <div class="btn-area" ref="detlArea">
                <el-button plain size="mini" type="success" @click="addRefCode">新增</el-button>
                <el-button plain size="mini" type="primary" @click="editRefCode">编辑</el-button>
                <el-button plain size="mini" type="danger" @click="delRefCode">删除</el-button
                >
              </div>-->
              <el-table
                :height="detlHeight"
                :data="currentCodeList"
                highlight-current-row
                @row-click="getCurrentCodeRow"
                border
                :header-cell-style="{
                  textAlign: 'center',
                }"
                :cell-style="{}"
              >
                <el-table-column show-overflow-tooltip type="index" :index="indexMethodDet" label="序号" width="60" align="center"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip width="120" align="left" prop="demandCode" label="需求编号"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="brand" label="货物品牌"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="dailyOutput" label="规格"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="product" align="center" label="产品大类"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="kind" align="center" label="品种"></el-table-column>
                <!-- <el-table-column show-overflow-tooltip align="center" prop="goodsCode" label="货物编码"></el-table-column> -->
                <el-table-column show-overflow-tooltip align="center" prop="transportType" label="运输类型"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="transportMode" align="center" label="运输方式"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="transportQuantity" label="运输数量(吨)" width="130"></el-table-column>
                <!-- <el-table-column show-overflow-tooltip align="center" prop="specialRequire" label="特殊要求"></el-table-column> -->
                <el-table-column show-overflow-tooltip align="center" prop="dptName" label="需求来源"></el-table-column>
                <el-table-column size="mini" show-overflow-tooltip prop="remark" align="center" label="备注"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" width="150" label="操作">
                  <template slot-scope="scope">
                    <el-button size="mini" type="primary" plain @click="showTransportMethod(scope.row)">线路详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- <div>
                <el-pagination class="pagination" small background
                  @size-change="handleSizeChangeA"
                  @current-change="handleCurrentChangeA"
                  :current-page="currentPage"
                  :page-sizes="[30, 60, 90, 120]"
                  :page-size="30"
                  layout="sizes, prev, pager, next, jumper, total"
                  :total="pageTotal">
                </el-pagination>
              </div>-->
            </div>
          </template>
        </split-pane>
      </div>
    </template>

    <!-- 审核弹框 -->
    <el-dialog
      width="80%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-el-drag-dialog
      title="审核信息"
      :visible.sync="RefTypeDialogVisible"
      v-if="RefTypeDialogVisible"
      :before-close="auditClose"
    >
      <el-form label-position="right" :model="RefTypeData" ref="RefTypeData" :rules="RefTypeDataRules" label-width="10rem" size="mini">
        <el-row class="dialog-row">
          <el-col :span="8">
            <el-form-item label="标的编号:" prop="bidCode">
              <el-input v-model="RefTypeData.bidCode" readonly="ture"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标的类型:" prop="bidType">
              <el-input v-model="RefTypeData.bidType" readonly="ture" clearable filterable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标的名称:" prop="bidName">
              <el-input v-model="RefTypeData.bidName" readonly="ture" placeholder="请输入标的名称" clearable filterable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="dialog-row">
          <el-col :span="8">
            <el-form-item label="运输总量:" prop="bidAmount">
              <el-input v-model="RefTypeData.bidAmount" readonly="ture" placeholder="请输入运输总量" filterable clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="竞价方式:" prop="bidQuotations">
              <el-input v-model="RefTypeData.bidQuotations" readonly="ture" clearable filterable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单价竞价范围:" prop="bidOffer">
              <el-input v-model="RefTypeData.bidOffer" readonly="ture" maxlength="8" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注:" prop="bidRemark">
              <el-input type="textarea" readonly="ture" v-model="RefTypeData.bidRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div class="tableTitle">需求信息</div>
      <div>
        <el-table
          :data="currentCodeList"
          :height="detlHeight"
          highlight-current-row
          border
          :row-style="changeRowBgColor"
          :header-cell-style="{
            textAlign: 'center',
          }"
          :cell-style="{}"
        >
          <el-table-column show-overflow-tooltip type="index" :index="indexMethodDet" label="序号" width="60" align="center"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip width="120" align="left" prop="demandCode" label="需求编号"></el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="brand" label="货物品牌"></el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="dailyOutput" label="规格"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="product" align="center" label="产品大类"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="kind" align="center" label="品种"></el-table-column>
          <!-- <el-table-column show-overflow-tooltip align="center" prop="goodsCode" width="120" label="货物编码"></el-table-column> -->
          <el-table-column show-overflow-tooltip align="center" prop="transportType" label="运输类型"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="transportMode" align="center" label="运输方式"></el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="transportQuantity" width="130" label="运输数量(吨)"></el-table-column>
          <!-- <el-table-column show-overflow-tooltip align="center" prop="specialRequire" label="特殊要求"></el-table-column> -->
          <el-table-column show-overflow-tooltip align="center" prop="dptName" label="需求来源"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="remark" align="center" label="备注"></el-table-column>
          <el-table-column align="center" width="360" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" plain @click="edit(scope.row)">编辑</el-button>
              <el-button size="mini" type="primary" plain @click="showTransportMethod(scope.row)">线路详情</el-button>
              <el-button size="mini" type="primary" plain @click="showHistory(scope.row)">驳回历史</el-button>
              <el-button size="mini" type="primary" plain @click="refuse(scope.row)">驳回</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- <br/>
        <el-form  :model="RefTypeData" ref="RefTypeData" :rules="RefTypeDataRules"  label-width="10rem">
            <el-row>
              <el-col :span="22">
                <el-form-item label="驳回意见:" prop="bidAuditOpinion">
                    <el-input type="textarea"  v-model="RefTypeData.bidAuditOpinion"></el-input>
                  </el-form-item>
              </el-col>
            </el-row>
      </el-form>-->
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="auditClose">关闭</el-button>
        <!-- <el-button size="mini" type="primary" @click="rejectTrue">驳回</el-button> -->
        <el-button size="mini" type="primary" @click="auditTrue">确认审核</el-button>
      </div>
    </el-dialog>

    <el-dialog
      width="40%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-el-drag-dialog
      title="线路详情"
      :visible.sync="tranDialogInfoDialogVisible"
      v-if="tranDialogInfoDialogVisible"
      :before-close="handleTypeDialogClose"
      :show-close="false"
    >
      <el-table
        :data="tranDialogInfoList"
        :height="detlHeight"
        highlight-current-row
        border
        :header-cell-style="{
          textAlign: 'center',
        }"
        :cell-style="{}"
      >
        <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="起始地" prop="site"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="目的地" prop="destination"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button
          size="mini"
          type="primary"
          @click="
            tranDialogInfoDialogVisible = false
            tranDialogInfoList = []
          "
          >关闭</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      width="1200px"
      top="5vh"
      v-dialogDrag
      v-el-drag-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="showDialog"
      :visible.sync="showDialog"
      :title="operate"
    >
      <v-dialog :dialogmode="operate" @closeEdit="closeEdit" @save="saveFltInfo" @dialogSave="dialogSave" :flt_info="currentFltInfo"></v-dialog>
    </el-dialog>

    <!-- 驳回需求dialog -->
    <el-dialog
      v-dialogDrag
      :title="refuseDialog.title"
      :visible.sync="refuseDialog.show"
      width="30%"
      v-el-drag-dialog
      destroy-on-close
      :close-on-click-modal="false"
      top="30vh"
    >
      <el-form :model="refuseFrom.data" :rules="refuseFrom.rules" ref="refuseFromRef">
        <el-form-item prop="refuseMsg">
          <el-row>
            <el-col :span="24">
              <el-input v-model="refuseFrom.data.refuseMsg" type="textarea" placeholder="请输入驳回意见" maxlength="200"></el-input>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button plain size="mini" type="primary" @click="refuseClose">关闭</el-button>
        <el-button size="mini" type="primary" @click="refuseConfirm">保存</el-button>
      </span>
    </el-dialog>

    <!-- 驳回历史 -->
    <el-dialog
      v-dialogDrag
      :title="HisDialogInfo.title"
      :visible.sync="HisDialogInfo.show"
      width="50%"
      v-el-drag-dialog
      destroy-on-close
      :close-on-click-modal="false"
      top="30vh"
    >
      <el-table :data="HisDialogInfo.table.data" border height="200">
        <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="驳回信息" prop="sfdoMessage"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="驳回人" prop="sfdoCreator"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="驳回时间" prop="sfdoCreatetime"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click=";(HisDialogInfo.show = false), (HisDialogInfo.table.data = []), (BoHcount = '')">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import VDialog from './dialog'
import {
  quertLineInfo,
  queryBiddingList,
  auditBiddingMethod,
  editBiddingQuantityMethod,
  bidListDetail,
  queryDemandLine,
  queryDemandList,
  refuseDemand,
  queryHistory,
  overRuleBiddingMethod,
} from '@/request/api'
import resizeMixin from '@/mixins/resize'
import isAuth from '@/mixins/buttonAuth'
import paginationMixin from '@/mixins/pagination'
import scrollChange from '@/utils/onscroll.js'
import buttonName from '@/components/buttonName/button-name.vue'
export default {
  mixins: [resizeMixin, paginationMixin, isAuth],
  components: {
    VDialog,
    buttonName,
  },
  data() {
    var RVNAME = (rule, value, callback) => {
      // 获得字符串实际长度，中文2，英文1
      var realLength = 0,
        len = value.length,
        charCode = -1
      for (var i = 0; i < len; i++) {
        charCode = value.charCodeAt(i)
        if (charCode >= 0 && charCode <= 128) realLength += 1
        else realLength += 2
      }
      if (realLength > 32) {
        return callback(new Error('最多为32位'))
        // this.companyName = cutstr(this.companyName, 60);
      } else {
        return callback()
      }
    }
    var RVREMARK = (rule, value, callback) => {
      // 获得字符串实际长度，中文2，英文1
      var realLength = 0,
        len = value.length,
        charCode = -1
      for (var i = 0; i < len; i++) {
        charCode = value.charCodeAt(i)
        if (charCode >= 0 && charCode <= 128) realLength += 1
        else realLength += 2
      }
      if (realLength > 128) {
        return callback(new Error('最多为128位'))
        // this.companyName = cutstr(this.companyName, 60);
      } else {
        return callback()
      }
    }
    return {
      showDialog: false,
      operate: '',
      queryParam: {
        bidCode: '', // 标的编号
        bidAuditstatus: '', // 标的审核状态
      },
      diaTableData: [], // 弹出框需求信息
      statusList: [
        { code: 'N', name: '未审核' },
        { code: 'Y', name: '已审核' },
      ],
      kinds: {
        BROW: '赤砂糖',
        TWOW: '二级白砂糖',
        ONEW: '一级白砂糖',
      },
      currentPage: 1,
      pageSize: 30,
      pageTotal: 0,

      //需求驳回
      refuseDialog: {
        show: false,
        title: '',
        currentData: {},
      },
      //需求历史
      dTable: {
        currentData: {},
      },

      refuseFrom: {
        data: {
          refuseMsg: '',
        },
        rules: {
          refuseMsg: [{ required: true, message: '请输入驳回意见', trigger: 'blur' }],
        },
      },

      // 驳回历史dialog
      HisDialogInfo: {
        title: '',
        show: false,
        table: {
          data: [],
        },
      },

      currentRow: {},
      codeentRow: '',
      typeHeight: -1,
      detlHeight: -1,
      CodeRCTUUID: false,
      CodeRVDOMAIN: false,
      checkedY: true,
      checkedN: false,
      flt: {
        rvDomain: '',
        rvName: '',
      },
      copyDomain: '',
      copyName: '',
      rleTypes: [],
      TypeMap: {
        updateType: 'baseCode.editClassify',
        createType: 'baseCode.addClassify',
      },
      CodeMap: {
        updateCode: 'baseCode.editCode',
        createCode: 'baseCode.addCode',
      },
      TypeDialogStatus: '',
      CodeDialogStatus: '',
      currentNode: {},
      currentType: {},
      TypeList: [],
      currentCodeList: [],
      tranDialogInfoList: [],
      tranDialogInfoDialogVisible: false, //线路详情Dialog
      currentCode: {},
      RefTypeDialogVisible: false, // 审核 Dialog
      RefCodeDialogVisible: false, // 基础代码 Dialog
      dialogForm: {},
      dialogText: {
        title: '',
        show: false,
        button: {
          t: '',
          f: '',
        },
        qeuryButtonShow: false,
        paginationShow: false,
      },
      // 代码分类
      RefTypeData: {}, // 代码分类 dialog内的form([A-Z]|\d)[0-9a-zA-Z]
      rules: {
        RV_DOMAIN: [
          { min: 1, max: 4, message: '至多输入4 个字符', trigger: 'change' },
          {
            pattern: /^([^\u4e00-\u9fa5])+$/,
            message: '禁止输入中文',
            trigger: 'change',
          },
        ],
        RV_NAME: [
          { validator: RVNAME, trigger: 'change' },
          {
            pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
            message: '只能输入中文字母数字',
            trigger: 'change',
          },
        ],
      },
      RefTypeDataRules: {
        rvDomain: [
          // { validator: RVDOMAIN, trigger: 'change' },
          { min: 1, max: 4, message: '至多输入4个字符', trigger: 'change' },
          { required: true, message: '请填写类型编号', trigger: 'blur' },
          // {
          //   pattern: /^([^\u4e00-\u9fa5])+$/,
          //   message: '禁止输入中文',
          //   trigger: 'change'
          // }
        ],
        rvName: [
          { required: true, message: '请填写类型名称', trigger: 'blur' },
          { validator: RVNAME, trigger: 'change' },
          {
            pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
            message: '只能输入中文字母数字',
            trigger: 'change',
          },
        ],
        rvIsvalid: [{ required: true, message: '请选择有效标志', trigger: 'blur' }],
        rvRemark: [{ validator: RVREMARK, trigger: 'change' }],
      },
      // 基础代码
      RefCodeData: {}, // 代码分类 dialog内的form
      RefCodeDataRules: {
        rvDomain: [{ required: true, message: '请选择代码类型', trigger: 'change' }],
        rvLowValue: [
          { min: 1, max: 4, message: '至多输入4个字符', trigger: 'change' },
          {
            pattern: /^([^\u4e00-\u9fa5])+$/,
            message: '禁止输入中文',
            trigger: 'change',
          },
          { required: true, message: '请填写代码编号', trigger: 'blur' },
        ],
        rvCmeaning: [
          { required: true, message: '请填写代码名称', trigger: 'blur' },
          { validator: RVNAME, trigger: 'change' },
          // {
          //   pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
          //   message: '只能输入中文字母数字',
          //   trigger: 'change'
          // }
        ],
        rvIsvalid: [{ required: true, message: '请选择有效标志', trigger: 'blur' }],
      },
      currentFltInfo: {},
      biddingQuantity: 0,
    }
  },
  created() {
    this.resize = () => {
      this.typeHeight = this.$refs.topType.offsetHeight - 80
      // 70
      this.detlHeight = this.$refs.bottomCode.offsetHeight - 70
      // 130
    }
  },
  mounted() {
    let demandWrapper = document.querySelector('.demand .el-table__body-wrapper') // 新增滚动条监听事件
    scrollChange(demandWrapper)
  },
  beforeMount() {
    this.refreshList()
  },
  computed: {
    grandson() {
      var dataList = []
      var number
      var arr = this.$route.path.split('/')
      number = arr.length - 1
      dataList = this.$store.state.user.permList
      for (var i = 0; i < dataList.length; i++) {
        for (var f = 0; f < dataList[i].Children.length; f++) {
          if (dataList[i].Children[f].MDL_CODE == arr[number]) {
            return dataList[i].Children[f].Grandson
          }
        }
      }
      return []
    },
    disableType() {
      return this.TypeDialogStatus === 'updateType'
    },
  },
  methods: {
    changeRowBgColor({ row, rowIndex }) {
      let styleJson = {}
      if (row.isEdit === 'Y') {
        styleJson = { 'background-color': 'yellow' }
      }
      return styleJson
    },

    //调取父组件方法
    clickEventDom(item) {
      if (item.mdlCode === 'auditButton') {
        this.auditButton()
      } else if (item.mdlCode === 'delAuditButton') {
        this.delAuditButton()
      }
    },

    // 审核弹窗编辑需求
    edit(value) {
      this.operate = '编辑'
      this.biddingQuantity = value.transportQuantity
      queryDemandList({ sugarId: value.sugarId }).then(res => {
        if (res.success === '1') {
          this.currentFltInfo = res.data[0]
          quertLineInfo({ sugarId: value.sugarId }).then(res => {
            res.data.forEach(item => {
              item.status = '1'
            })
            this.currentFltInfo.demandLineInfos = res.data
          })
          this.showDialog = true
        } else {
          this.$message.error({
            message: '操作失败',
          })
        }
      })
    },

    // 驳回需求按钮
    refuse(val) {
      this.refuseDialog.currentData = val
      this.refuseDialog.title = '驳回'
      this.refuseDialog.show = true
    },

    // 驳回确认
    refuseConfirm() {
      this.$refs['refuseFromRef'].validate(valid => {
        if (valid) {
          refuseDemand({
            demandCode: this.refuseDialog.currentData.demandCode,
            sfdRefuseMsg: this.refuseFrom.data.refuseMsg,
            status: 'BOH',
            sugarId: this.refuseDialog.currentData.sugarId,
          }).then(res => {
            this.$message.success('驳回成功')
            overRuleBiddingMethod({
              bidId: this.RefTypeData.bidId,
              bidAmount: this.refuseDialog.currentData.transportQuantity,
            }).then(res => {
              if (res.success != '1') {
                this.$message.error('更改运输数量失败')
              }
            })
            //减法
            var arg1 = this.RefTypeData.bidAmount
            var arg2 = this.refuseDialog.currentData.transportQuantity
            var r1, r2, m, n
            try {
              r1 = arg1.toString().split('.')[1].length
            } catch (e) {
              r1 = 0
            }
            try {
              r2 = arg2.toString().split('.')[1].length
            } catch (e) {
              r2 = 0
            }
            m = Math.pow(10, Math.max(r1, r2))
            n = r1 >= r2 ? r1 : r2
            this.RefTypeData.bidAmount = ((arg1 * m - arg2 * m) / m).toFixed(n)
            this.getCurrentTypeRow(this.RefTypeData)
            this.refuseClose()
          })
        }
      })
    },
    // 驳回关闭
    refuseClose() {
      this.refuseDialog.currentData = {}
      this.refuseFrom.data = {}
      this.$refs['refuseFromRef'].resetFields()
      this.refuseDialog.show = false
    },

    //审核关闭
    auditClose() {
      this.RefTypeDialogVisible = false
      this.RefTypeData = {}
      this.refreshList()
    },

    // dialog 查看历史记录
    showHistory(val) {
      this.dTable.currentData = val
      this.initHisMethodTable()
      this.HisDialogInfo.title = '驳回历史'
      this.HisDialogInfo.show = true
    },

    // 初始化历史驳回记录
    initHisMethodTable() {
      queryHistory({
        demandCode: this.dTable.currentData.demandCode,
      }).then(res => {
        if (res.success == 1) {
          this.HisDialogInfo.table.data = res.data.list
          this.BoHcount = res.data.number
        }
      })
    },

    //点击弹窗保存 关闭弹窗 请求列表接口
    dialogSave(box) {
      if (this.currentFltInfo.transportQuantity != this.biddingQuantity) {
        editBiddingQuantityMethod({
          bidId: this.RefTypeData.bidId,
        }).then(res => {
          if (res.success == 1) {
            this.RefTypeData.bidAmount = res.msg
          }
        })
      }
      this.showDialog = box.info
      this.getCurrentTypeRow(this.RefTypeData)
    },
    // 关闭弹窗
    closeEdit() {
      this.showDialog = false
    },

    dialogBeforeClose(done) {
      this.$confirm('确认关闭?')
        .then(() => {
          done()
        })
        .catch(() => {})
    },
    checkCode() {
      this.flt.RV_DOMAIN = this.flt.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    typecheck() {
      this.RefTypeData.RV_DOMAIN = this.RefTypeData.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    codecheck() {
      this.RefCodeData.RV_DOMAIN = this.RefCodeData.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    uppercase(key) {
      this.$refs.typePagination.lastEmittedPage = 1
      this.$refs.codePagination.lastEmittedPage = 1
      this.flt[key] = this.flt[key].toUpperCase()
    },
    // typeuppercase(key) {
    //   this.RefTypeData[key] = this.RefTypeData[key].toUpperCase()
    // },
    codeuppercase(key) {
      this.RefCodeData[key] = this.RefCodeData[key].toUpperCase()
    },
    getFltType() {
      addCodeTableXL({}).then(res => {
        if (res.success === '1') {
          this.rleTypes = res.data
        }
      })
    },
    searchType() {
      this.$refs.queryParam.validate(valid => {
        if (valid) {
          this.Pagination.currentPage = 1
          this.getList(this.Pagination.currentPage, this.Pagination.pageSize, this.updatePaginationTotal)
        }
      })
    },
    //获取列表
    getList(currentPage, pageSize, updateTotal) {
      this.currentCodeList = []
      this.RefTypeData = {}
      queryBiddingList({
        bidCode: this.queryParam.bidCode,
        bidAuditstatus: this.queryParam.bidAuditstatus,
        PageIndexs: this.Pagination.currentPage.toString(),
        PageSizes: this.Pagination.pageSize.toString(),
      }).then(response => {
        this.TypeList = response.data
        updateTotal(Number(response.total))
      })
    },

    // 审核
    auditButton() {
      if (this.currentCodeList.length == 0) {
        this.$alert('选择的信息无需求信息，不可审核！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }

      if (Object.keys(this.RefTypeData).length == 0) {
        this.$alert('请选择需要审核的信息！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }

      if (this.RefTypeData.bidAuditstatus === 'Y') {
        this.$alert('请选择未审核的信息！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      this.TypeDialogStatus = 'createType'
      this.RefTypeDialogVisible = true
    },
    // 取消审核
    delAuditButton() {
      if (Object.keys(this.RefTypeData).length == 0) {
        this.$alert('请选择需要取消审核的信息！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }

      if (this.RefTypeData.bidAuditstatus === 'N') {
        this.$alert('请选择已审核的信息！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      this.$confirm('您确定要取消审核该信息吗？', '提示', {
        confirmButtonText: '确定',
      }).then(() => {
        auditBiddingMethod({ bidId: this.currentType.bidId, bidAuditstatus: 'N' }).then(res => {
          if (res.success === '1') {
            this.$message({
              type: 'success',
              message: '取消审核成功',
            })
            this.RefTypeDialogVisible = false
            this.RefTypeData = {}
            this.refreshList()
          }
        })
      })
    },

    // 确认审核
    auditTrue() {
      auditBiddingMethod({ bidId: this.RefTypeData.bidId, bidAuditstatus: 'Y', bidAuditOpinion: this.RefTypeData.bidAuditOpinion }).then(res => {
        if (res.success === '1') {
          this.$message({
            type: 'success',
            message: '审核成功',
          })
          this.RefTypeDialogVisible = false
          this.RefTypeData = {}
          this.refreshList()
        }
      })
    },

    // 驳回
    rejectTrue() {
      if (!this.RefTypeData.bidAuditOpinion) {
        this.$alert('请填写驳回意见！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      auditBiddingMethod({ bidId: this.RefTypeData.bidId, bidStatus: 'PTBH', bidAuditstatus: 'N', bidAuditOpinion: this.RefTypeData.bidAuditOpinion }).then(
        res => {
          if (res.success === '1') {
            this.$message({
              type: 'success',
              message: '驳回成功',
            })
            this.RefTypeDialogVisible = false
            this.RefTypeData = {}
            this.refreshList()
          }
        }
      )
    },

    getCurrentTypeRow(row) {
      this.currentPage = 1
      this.pageSize = 30
      this.pageTotal = 0
      this.currentType = row
      this.RefTypeData = Object.assign({}, row)
      bidListDetail({
        bidId: row.bidId,
      }).then(res => {
        if (res.success == 1) {
          this.currentCodeList = res.data
        }
      })
    },

    // dialog 查看线路详细信息
    showTransportMethod(val) {
      queryDemandLine({
        sugarId: val.sugarId,
      }).then(res => {
        if (res.success == 1) {
          this.tranDialogInfoList = res.data
        }
      })
      this.tranDialogInfoDialogVisible = true
    },

    // 点击基础代码表格的一行，获取到当前行的信息
    getCurrentCodeRow(row) {
      this.codeentRow = '1'
      this.currentCode = row
    },

    handleSizeChangeA(val) {
      this.pageSize = val
      this.getRefCode()
    },
    handleCurrentChangeA(val) {
      this.currentPage = val
      this.getRefCode()
    },

    handleTypeDialogClose() {
      this.RefTypeDialogVisible = false
      this.tranDialogInfoDialogVisible = false
    },
    handleCodeDialogClose() {
      this.RefCodeDialogVisible = false
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .splitter-pane-resizer.horizontal {
  margin-top: -15px;
}
.app-container {
  overflow: hidden;
  background-color: #fff;
  position: relative;
  height: 100%;
}
.tree {
  padding-right: 20px;
  font-size: 1.4rem;
}
.right-detail {
  height: 100%;
  .top-type {
    width: 100%;
    height: 100%;
    table {
      max-width: 100%;
      font-size: 1.4rem;
    }
  }
  .bottom-code {
    width: 100%;
    height: 100%;
  }
}
.codeNumberCode {
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 20px;
}
.basicInfoBox {
  border: 1px solid #cccccc;
  border-radius: 5px;
  padding-top: 25px;
  padding-bottom: 10px;
}
</style>
